{% extends "base.html" %}
{% block title %}存款类型管理{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">
            <i class="bi bi-piggy-bank-fill"></i> 存款类型管理
        </h1>
        <div class="d-flex">
            <form method="GET" action="{{ url_for('admin_deposit_types') }}" class="me-3">
                <div class="input-group">
                    <input type="text" name="search" class="form-control"
                           placeholder="搜索类型名称或描述" value="{{ search }}">
                    <button class="btn btn-outline-secondary" type="submit">
                        <i class="bi bi-search"></i>
                    </button>
                    {% if search %}
                    <a href="{{ url_for('admin_deposit_types') }}" class="btn btn-outline-danger">
                        <i class="bi bi-x"></i>
                    </a>
                    {% endif %}
                </div>
            </form>
            <a href="{{ url_for('admin_add_deposit_type') }}" class="btn btn-primary">
                <i class="bi bi-plus-circle"></i> 添加
            </a>
        </div>
    </div>

    <!-- 存款类型列表 -->
    <div class="card shadow">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>ID</th>
                            <th>类型名称</th>
                            <th>描述</th>
                            <th class="text-end">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% if not deposit_types %}
                        <tr>
                            <td colspan="4" class="text-center text-muted py-4">
                                {% if search %}
                                没有找到匹配的存款类型
                                {% else %}
                                暂无存款类型记录
                                {% endif %}
                            </td>
                        </tr>
                        {% endif %}

                        {% for deposit in deposit_types %}
                        <tr>
                            <td>{{ deposit.savingID }}</td>
                            <td>{{ deposit.savingName }}</td>
                            <td class="text-truncate" style="max-width: 200px;"
                                title="{{ deposit.descrip }}">
                                {{ deposit.descrip or '-' }}
                            </td>
                            <td class="text-end">
                                <div class="btn-group btn-group-sm">
                                    <a href="{{ url_for('admin_edit_deposit_type', saving_id=deposit.savingID) }}"
                                       class="btn btn-outline-primary"
                                       data-bs-toggle="tooltip" title="编辑">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <a href="{{ url_for('admin_delete_deposit_type', saving_id=deposit.savingID) }}"
                                       class="btn btn-outline-danger"
                                       data-bs-toggle="tooltip" title="删除"
                                       onclick="return confirm('确定要删除存款类型 {{ deposit.savingName }} 吗？')">
                                        <i class="bi bi-trash"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
// 启用工具提示
document.addEventListener('DOMContentLoaded', function() {
    var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
    var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl)
    })
})
</script>
{% endblock %}